package cn.ibizlab.odoo.core.odoo_base.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Ibase_automation_lead_test;
import cn.ibizlab.odoo.core.odoo_base.domain.Base_automation_lead_test;
import cn.ibizlab.odoo.core.odoo_base.filter.Base_automation_lead_testSearchContext;
import cn.ibizlab.odoo.core.odoo_base.service.IBase_automation_lead_testService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[自动化规则测试] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Base_automation_lead_testServiceImpl implements IBase_automation_lead_testService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Ibase_automation_lead_testClientService base_automation_lead_testClientService;

    @Override
    public void updateBatch(List<Base_automation_lead_test> base_automation_lead_tests, int batchSize) {

        //base_automation_lead_testClientService.updateBatch(base_automation_lead_tests,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Ibase_automation_lead_test clientModel = base_automation_lead_testClientService.createModel();
        clientModel.setId(id);
        base_automation_lead_testClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public boolean create(Base_automation_lead_test base_automation_lead_test) {
        boolean bOk = false ;
        Ibase_automation_lead_test clientModel = this.convert2Model(base_automation_lead_test,null);
        base_automation_lead_testClientService.create(clientModel) ;
        this.convert2Domain(clientModel,base_automation_lead_test);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void createBatch(List<Base_automation_lead_test> base_automation_lead_tests, int batchSize) {

                        //base_automation_lead_testClientService.createBatch(base_automation_lead_tests,batchSize) ;

    }

    @Override
    public boolean update(Base_automation_lead_test base_automation_lead_test) {
        boolean bOk = false ;
        Ibase_automation_lead_test clientModel = this.convert2Model(base_automation_lead_test,null);
        base_automation_lead_testClientService.update(clientModel) ;
        this.convert2Domain(clientModel,base_automation_lead_test) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //base_automation_lead_testClientService.removeBatch(base_automation_lead_tests) ;

    }

    @Override
    public Base_automation_lead_test get(Integer id) {
        Ibase_automation_lead_test clientModel = base_automation_lead_testClientService.createModel();
        clientModel.setId(id);
        base_automation_lead_testClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Base_automation_lead_test get(Base_automation_lead_test base_automation_lead_test) {
        Base_automation_lead_test retbase_automation_lead_test = this.get(base_automation_lead_test.getId()) ;
    	BeanCopier copier=BeanCopier.create(retbase_automation_lead_test.getClass(), base_automation_lead_test.getClass(), false);
        copier.copy(retbase_automation_lead_test, base_automation_lead_test, null);
        return base_automation_lead_test ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Base_automation_lead_test> searchDefault(Base_automation_lead_testSearchContext context) {
        List<Base_automation_lead_test> list = new ArrayList<Base_automation_lead_test>();
        Page<cn.ibizlab.odoo.core.client.model.Ibase_automation_lead_test> clientModelList = base_automation_lead_testClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ibase_automation_lead_test clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Base_automation_lead_test>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据联系人查询
     */
    @Override
    public Page<Base_automation_lead_test> selectByOdoo_partner(Integer id){
        Base_automation_lead_testSearchContext context = new Base_automation_lead_testSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Base_automation_lead_test> list = new ArrayList<Base_automation_lead_test>();
        Page<cn.ibizlab.odoo.core.client.model.Ibase_automation_lead_test> clientModelList = base_automation_lead_testClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ibase_automation_lead_test clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Base_automation_lead_test>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Base_automation_lead_test> selectByOdoo_create(Integer id){
        Base_automation_lead_testSearchContext context = new Base_automation_lead_testSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Base_automation_lead_test> list = new ArrayList<Base_automation_lead_test>();
        Page<cn.ibizlab.odoo.core.client.model.Ibase_automation_lead_test> clientModelList = base_automation_lead_testClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ibase_automation_lead_test clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Base_automation_lead_test>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Base_automation_lead_test> selectByOdoo_user(Integer id){
        Base_automation_lead_testSearchContext context = new Base_automation_lead_testSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Base_automation_lead_test> list = new ArrayList<Base_automation_lead_test>();
        Page<cn.ibizlab.odoo.core.client.model.Ibase_automation_lead_test> clientModelList = base_automation_lead_testClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ibase_automation_lead_test clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Base_automation_lead_test>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Base_automation_lead_test> selectByOdoo_write(Integer id){
        Base_automation_lead_testSearchContext context = new Base_automation_lead_testSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Base_automation_lead_test> list = new ArrayList<Base_automation_lead_test>();
        Page<cn.ibizlab.odoo.core.client.model.Ibase_automation_lead_test> clientModelList = base_automation_lead_testClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ibase_automation_lead_test clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Base_automation_lead_test>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Ibase_automation_lead_test convert2Model(Base_automation_lead_test domain , Ibase_automation_lead_test model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = base_automation_lead_testClientService.createModel() ;
        }

         if(domain.getIs_assigned_to_adminDirtyFlag())
            model.setIs_assigned_to_admin(domain.getIs_assigned_to_admin());
         if(domain.getLine_idsDirtyFlag())
            model.setLine_ids(domain.getLine_ids());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getDate_action_lastDirtyFlag())
            model.setDate_action_last(domain.getDate_action_last());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getActiveDirtyFlag())
            model.setActive(domain.getActive());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getStateDirtyFlag())
            model.setState(domain.getState());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getDeadlineDirtyFlag())
            model.setDeadline(domain.getDeadline());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getPriorityDirtyFlag())
            model.setPriority(domain.getPriority());
         if(domain.getPartner_id_textDirtyFlag())
            model.setPartner_id_text(domain.getPartner_id_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getCustomerDirtyFlag())
            model.setCustomer(domain.getCustomer());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getUser_id_textDirtyFlag())
            model.setUser_id_text(domain.getUser_id_text());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getPartner_idDirtyFlag())
            model.setPartner_id(domain.getPartner_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getUser_idDirtyFlag())
            model.setUser_id(domain.getUser_id());
        return model ;
    }

    public Base_automation_lead_test convert2Domain( Ibase_automation_lead_test model ,Base_automation_lead_test domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Base_automation_lead_test();
        }

        if(model.getIs_assigned_to_adminDirtyFlag())
            domain.setIs_assigned_to_admin(model.getIs_assigned_to_admin());
        if(model.getLine_idsDirtyFlag())
            domain.setLine_ids(model.getLine_ids());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getDate_action_lastDirtyFlag())
            domain.setDate_action_last(model.getDate_action_last());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getActiveDirtyFlag())
            domain.setActive(model.getActive());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getStateDirtyFlag())
            domain.setState(model.getState());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getDeadlineDirtyFlag())
            domain.setDeadline(model.getDeadline());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getPriorityDirtyFlag())
            domain.setPriority(model.getPriority());
        if(model.getPartner_id_textDirtyFlag())
            domain.setPartner_id_text(model.getPartner_id_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getCustomerDirtyFlag())
            domain.setCustomer(model.getCustomer());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getUser_id_textDirtyFlag())
            domain.setUser_id_text(model.getUser_id_text());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getPartner_idDirtyFlag())
            domain.setPartner_id(model.getPartner_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getUser_idDirtyFlag())
            domain.setUser_id(model.getUser_id());
        return domain ;
    }


}
